package top.chmin.project.cloud.common.menu.auto;

// field import auto

import cn.hutool.core.bean.BeanUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.chmin.project.cloud.common.entity.Page;

/**
 * chmin
 * 2023-12-25 09:15:43
 * cloud-builder
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MenuService {

    @Resource
    MenuPlugin plugin;

    @Resource
    MenuDao menuDao;

// field labelDao auto

    public int save(MenuSave.Param param) {
        plugin.checkSave(param);
        Menu menu = BeanUtil.toBean(param, Menu.class);
        plugin.beforeSave(menu);
        int result = menuDao.save(menu);
        plugin.afterSave(param, menu, result);
        return result;
    }

    public int updateById(MenuUpdateById.Param param) {
        plugin.checkUpdateById(param);
        Menu menu = BeanUtil.toBean(param, Menu.class);
        plugin.beforeUpdateById(menu);
        int result = menuDao.updateById(menu);
        plugin.afterUpdateById(param, menu, result);
        return result;
    }

    public int deleteById(MenuDeleteById.Param param) {
        plugin.checkDeleteById(param);
        int result = menuDao.deleteById(param.getId());
        plugin.afterDeleteById(param, result);
        return result;
    }

    public MenuSelectById.Result selectById(MenuSelectById.Param param) {
        plugin.checkSelectById(param);
        MenuFPC fpc = new MenuFPC().id().eq(param.getId());
        plugin.beforeSelectById(param, fpc);
        MenuSelectById.Result result = menuDao.getFirst(fpc.toCondition(), MenuSelectById.Result.class);
        plugin.afterSelectById(param, result);
        return result;
    }

    public Page<MenuSelectPage.Result> selectPage(MenuSelectPage.Param param) {
        plugin.checkSelectPage(param);
        MenuFPC fpc = new MenuFPC();
        fpc = param.isDesc() ? fpc.id().desc() : fpc.id().asc();
        plugin.beforeSelectPage(param, fpc);
        Page<MenuSelectPage.Result> result = menuDao.getPageByCondition(fpc.toCondition(), MenuSelectPage.Result.class);
// field label auto
        plugin.afterSelectPage(param, result);
        return result;
    }

// entity select auto

// entity search auto

}
